package com.base.cn.platform.os.controller.web.user.center.member;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.service.manage.order.goods.OrderDetailsService;
import com.base.cn.platform.os.service.manage.user.member.CusUserMemberBuyRecordService;
import com.base.cn.platform.os.service.manage.user.member.CusUserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ll
 * @date 2018/5/30 11:33
 */
@Controller
@RequestMapping("/web/uc")
public class WebUserMemberController extends WebBaseController {
    @Autowired
    private CusUserMemberBuyRecordService cusUserMemberBuyRecordService;
    @Autowired
    private OrderDetailsService orderDetailsService;
    @Autowired
    private CusUserMemberService cusUserMemberService;

    /**
     * 会员
     * @param request
     * @return
     */
    @RequestMapping("/myMember")
    public String myMember(HttpServletRequest request){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String,Object> record =cusUserMemberBuyRecordService.queryUserBuyMemberRecord(userId);
        request.setAttribute("userMemberBuyRecord",record);
        return resultPage("/user/center/myAccount/u-myMember");
    }

    /**
     * 会员我的记录
     *
     * @param request
     * @return
     */
    @RequestMapping("/ajax/userMemberBuyRecord")
    public String userMemberBuyRecord(Model model, HttpServletRequest request,
                                      @RequestBody Map<String,Object> parmas,
                                      @RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        parmas.put("userId",userId);
        parmas.put("shopType","MEMBER");
        parmas.put("statusList","'SUCCESS','REFUND'");
        Map<String, Object> dataMap = orderDetailsService.findOrderDetailsPage(parmas,currentPage,false,true,false);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/center/myAccount/u-ajax-myMember");
    }


    /**
     *了解更多会员功能页面
     * @param request
     * @return
     */
    @RequestMapping("/member/queryMemberList")
    public String queryMemberList(HttpServletRequest request){
        return resultPage("/user/center/member/order-selectMember");
    }

    /**
     * 查询会员商品列表
     * @param model
     * @return
     */
    @RequestMapping("/member/ajax/ajaxQueryMemberList")
    public String ajaxQueryMemberList(Model model){
        Map<String,Object> params = new HashMap<>();
        params.put("status",1);
        params.put("memberType",1);
        List<Map<String,Object>> userMemberList = cusUserMemberService.queryUserMemberList(params);
        model.addAttribute("userMemberList",userMemberList);
        return resultPage("/user/center/member/ajax-member-list");
    }
}
